from sqlalchemy import (
    Boolean,
    Column,
    String,
)
from sqlalchemy.orm import relationship
from ..database import Base
from utils.id_util import generate_id
from .user_role_do import UserRoleModel

class UserModel(Base):
    __tablename__ = "users"

    id = Column(String, primary_key=True, default=generate_id, index=True)
    username = Column(String, unique=True, index=True)
    hashed_password = Column(String)
    is_active = Column(Boolean, default=True)
    is_superuser = Column(Boolean, default=False)

    user_roles = relationship("UserRoleModel", backref="user", cascade="all, delete-orphan")
    roles = relationship("RoleModel", secondary="user_roles", viewonly=True)